const cache = new Cache(config.timeout * 3)
const data = [0, 0, 0, 0, 0]

async function main(market, base, quote) {

	const url = `https://www.bitstamp.net/api/v2/ticker/${base}${quote}/`

	try {
		const {statusCode, body} = await Request.getAsync(url, {timeout: config.timeout, json: true})
		// console.log(url, statusCode, body)

		if (statusCode == 200) {
			data[0] = Number(body.last)
			data[1] = Number(body.ask)
			data[2] = Number(body.bid)
			cache.put('data', data)
		}
	} catch (error) {
		LOG([market, error.code || error.message || error])
	}

	await Promise.delay(config.timeout * 0.5)
	main(market, base, quote)
}

exports.init = main
exports.data = cache